package com.sonic.ws.services.settings;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.ws.WebServiceContext;

import com.sonic.db.dao.MQSettingsDAO;
import com.sonic.dto.ws.services.settings.MQSettingsRequest;
import com.sonic.dto.ws.services.settings.MQSettingsResponse;
import com.sonic.log.ejb.impl.MQLogger;
import com.sonic.ws.interfaces.settings.IMQSettingsService;

@WebService(name="SettingsService",
		serviceName="SettingsService", 
		portName="SettingsServicePort", 
		targetNamespace="com.sonic.mquotes.settings"
)
@SOAPBinding(
        style = SOAPBinding.Style.DOCUMENT,
        use = SOAPBinding.Use.LITERAL,
        parameterStyle = SOAPBinding.ParameterStyle.WRAPPED
)
@Stateless(mappedName="MQSettingsServiceRemote")
@Remote(IMQSettingsService.class)
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public class MQSettingsService implements IMQSettingsService {
	private static MQLogger logger = new MQLogger(MQSettingsService.class, "MQ-WS-SETTINGS");
	
	private MQSettingsDAO mqSettingsDAO;
	
	@SuppressWarnings("unused")
    @Resource
	private WebServiceContext context;
	  
	@PostConstruct
	public void init() {
		final String methodName = "init()";
		logger.debug(methodName, " --- Successfully invoked init() method.");		
		this.mqSettingsDAO = new MQSettingsDAO();
		logger.debug(methodName, " --- MQSettingsDAO Successfully created.");
	}
	
	@PreDestroy
	public void destroy() {
		final String methodName = "destroy()";
		logger.debug(methodName, " --- Successfully invoked destroy() method.");		
		this.mqSettingsDAO.releaseResources();
		logger.debug(methodName, " --- MQSettingsDAO resources have been successfully released.");
	}
	
	@WebMethod(operationName="getSettings")
	public @WebResult(name="settingsResponse", targetNamespace="com.sonic.mquotes.settings") MQSettingsResponse getSettings(@WebParam(name="settingsRequest", targetNamespace="com.sonic.mquotes.settings") MQSettingsRequest request) {
		final String methodName = "getSettings()";
		logger.debug(methodName, " --- Get settings for client's id: " + request.getClientID());	
		return this.mqSettingsDAO.getSettings(request);
    }

//	@WebMethod(operationName="savePAPSettings")
//	public @WebResult(name="saveSettingsResponse", targetNamespace="com.sonic.mquotes.settings") MQSaveSettingsResponse savePAPSettings(@WebParam(name="savePAPSettingsRequest", targetNamespace="com.sonic.mquotes.settings") MQSavePAPSettingsRequest request) {
//		final String methodName = "savePAPSettings()";
//		logger.debug(methodName, " --- Save PAP settings for client's id: " + request.getClientID());	
//		return this.mqSettingsDAO.savePAPSettings(request);
//    }
//
//	@WebMethod(operationName="saveSecuritySettings")
//	public @WebResult(name="saveSettingsResponse", targetNamespace="com.sonic.mquotes.settings") MQSaveSettingsResponse saveSecuritySettings(@WebParam(name="saveSecuritySettingsRequest", targetNamespace="com.sonic.mquotes.settings") MQSaveSecuritySettingsRequest request) {
//		final String methodName = "saveSecuritySettings()";
//		logger.debug(methodName, " --- Save security settings for client's id: " + request.getClientID());	
//		return this.mqSettingsDAO.saveSecuritySettings(request);
//    }
//
//	@WebMethod(operationName="saveTableSettings")
//	public @WebResult(name="saveSettingsResponse", targetNamespace="com.sonic.mquotes.settings") MQSaveSettingsResponse saveTableSettings(@WebParam(name="saveTableSettingsRequest", targetNamespace="com.sonic.mquotes.settings") MQSaveTableSettingsRequest request) {
//		final String methodName = "saveTableSettings()";
//		logger.debug(methodName, " --- Save table settings for client's id: " + request.getClientID());	
//		return this.mqSettingsDAO.saveTableSettings(request);
//    }
}